home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: Pointers to structures question.
- Date: Mon, 25 Mar 96 14:55:58 GMT
- Organization: none
- Message-ID: <827765758snz@genesis.demon.co.uk>
- References: <4j2drs$q3r@dfw-ixnews3.ix.netcom.com> <3154F14C.35ED@ix.netcom.com>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <3154F14C.35ED@ix.netcom.com> bland@ix.netcom.com "Brian Land" writes:
-
- >Andrew Heiz wrote:
- >>
- >> Hi there,
- >>
- >> Thanks for reading.
- >>
- >> I have a simple question about using pointers to structures. I am
- >> imputing data into a structure using:
- >>
- >> gets(struct.element);
- >>
- >> My question is in how to reference the structure element with a
- >> pointer. How do I do this?
-
- char *ptr = struct.element; /* Substituting the real name for struct */
-
- and then examine the first element of the array with, for example,
-
- ptr[0] or *ptr
-
- >>
- >
- >
- >How about....
- >
- > gets( &(struct.element) );
-
- No, a legal argument for gets() must be a pointer to the first element of
- an array of char. Therefore struct.element must be either an array of char
- or a pointer to char suitabbly set to point into another array. Either way
- you must write this as:
-
- gets(struct.element);
-
- However using gets() in the first place strongly indicates Ansrew hasn't read
- the comp.lang.c FAQ.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-